package com.util;

import com.util.interfaces.IdAndName;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.Reader;

public class GetPrint {
    public static<T extends IdAndName> void get(String File, T[] objects, T object) throws Exception{
        //将文件里面的值放入数组中的全能函数。
        Reader reader = new FileReader(File);
        BufferedReader bufferedReader = new BufferedReader(reader);
        for (int i = 0; i < File.length(); i++) {
            String s = bufferedReader.readLine();
            if (s != null){
                T newObj = (T) object.getClass().newInstance();//初始化泛型
                String substring1 = s.substring(0,s.indexOf("."));
                String substring2 = s.substring(s.indexOf(".")+1);
                newObj.setId(Integer.parseInt(substring1));
                newObj.setName(substring2);
                System.out.println();
                objects[i] = newObj;
            }
        }
    }

}
